package com.bilibili.service.impl;

import java.util.List;

import com.bilibili.dao.FollowDao;
import com.bilibili.dao.VideoDao;
import com.bilibili.dao.impl.FollowDaoImpl;
import com.bilibili.dao.impl.VideoDaoImpl;
import com.bilibili.entity.Follow;
import com.bilibili.entity.Page;
import com.bilibili.entity.Video;
import com.bilibili.service.VideoService;

public class VideoServiceImpl implements VideoService {
	private VideoDao videoDao = new VideoDaoImpl();
	VideoDao vd = new VideoDaoImpl();

	@Override
	public boolean insertVideo(Video video) {
		int rowNum = videoDao.insertVideo(video);
		return rowNum == 1;
	}

	@Override
	public int selectAllViewByUid(int uploaderId) {
		return videoDao.selectAllViewByUid(uploaderId);
	}

	@Override
	public List<Video> selectByAll(int uploaderId) {
		return videoDao.selectByAll(uploaderId);
	}

	@Override
	public Video selectVideoById(int videoId) {
		return videoDao.selectVideoById(videoId);
	}

	@Override
	public List<Video> selectVideosByIds(List<Integer> videoIds) {
		return videoDao.selectVideosByIds(videoIds);
	}

	@Override
	public int selectViewByUidAndDate(int uploaderId, java.util.Date nowDate) {
		return videoDao.selectViewByUidAndDate(uploaderId, nowDate);
	}

	public Video getVideoById(int videoId) {
		return videoDao.getVideoById(videoId);
	}

	FollowDao followDao = new FollowDaoImpl();

	@Override
	public boolean insertMyAttention(Follow follow) {
		// TODO Auto-generated method stub
		return followDao.insertMyAttention(follow) == 1;
	}

	public boolean deleteVideosByVideoId(int user_id, int VideoId) {
		// TODO Auto-generated method stub
		return videoDao.deleteVideosByVideoId(user_id, VideoId) == 1;
	}

	@Override
	public boolean deleteMyAttention(Follow follow) {
		// TODO Auto-generated method stub
		return followDao.deleteMyAttention(follow) == 1;
	}

	public Page<Video> selectAllVideo(Video v, int pageNum, int pageSize) {
		// TODO Auto-generated method stub
		List<Video> videoList = vd.selectAllVideo(v, pageNum, pageSize);
		int totalRows = vd.selectAllVideoNum(v);
		Page<Video> videoPage = new Page<Video>(videoList, pageNum, pageSize, totalRows);
		return videoPage;
	}

	@Override
	public int selectNotExamineVideoNum() {
		// TODO Auto-generated method stub
		return vd.selectNotExamineVideoNum();
	}

	@Override
	public boolean updateVideostate(Video v) {
		// TODO Auto-generated method stub
		return vd.updateVideostate(v) == 1;
	}

	@Override
	public int selectAllVideoNum() {
		// TODO Auto-generated method stub
		return vd.selectAllVideoNum();
	}
	

	@Override
	public boolean updateVideoStateByVideoId(int state, int videoId) {
		// TODO Auto-generated method stub
		return vd.updateVideoStateByVideoId(state,videoId) == 1;
	}
}